//
//  RealtimeTranslatorBarView.swift
//  GLUZSwift
//
//  Created by xyanl on 2025/4/11.
//

import UIKit
import Reusable

extension RealtimeTranslatorBarView: NibLoadable {}

class RealtimeTranslatorBarView: UIView {
    
    var didSelectedItemBlock: ((RealtimeTranslatorState) -> Void)?
    
    var state: RealtimeTranslatorState = .none {
        didSet {
            switch state {
            case .none:
                zhButton.backgroundColor = UIColor(hex: "43B4D2", 0.3)
                ruButton.backgroundColor = UIColor(hex: "43B4D2", 0.3)
                
            case .zh:
                zhButton.backgroundColor = UIColor(hex: "43B4D2")
                ruButton.backgroundColor = UIColor(hex: "43B4D2", 0.3)
                
            case .ru:
                zhButton.backgroundColor = UIColor(hex: "43B4D2", 0.3)
                ruButton.backgroundColor = UIColor(hex: "43B4D2")
                
            }
        }
    }
    
    @IBOutlet weak var zhButton: UIButton!
    @IBOutlet weak var ruButton: UIButton!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        addRoundedCorners(radius: 22)
        
        zhButton.adjustsImageWhenHighlighted = false
        ruButton.adjustsImageWhenHighlighted = false
        
        zhButton.sg.setImagePosition(.left, padding: 4)
        ruButton.sg.setImagePosition(.left, padding: 4)
    }
    
    @IBAction func changeAction(_ sender: UIButton) {
        if sender.tag == 0 {
            state = .zh
        } else {
            state = .ru
        }
        didSelectedItemBlock?(state)
    }
    
}
